package com.lxf.project;

import com.lxf.project.inteface.IHelloWorld;
import javassist.CtNewConstructor;
import org.apache.dubbo.config.*;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ApiProvider {

    public static void main(String[] args) {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setQosPort(22221);
        applicationConfig.setName("dubbo-demo-api-provider");
        Map<String,String> parameter = new HashMap<String,String>();
        parameter.put("mapping-type","metadata");
        applicationConfig.setParameters(parameter);
        ConfigCenterConfig centerConfig = new ConfigCenterConfig();
        centerConfig.setAddress("zookeeper://127.0.0.1:2181");
        MetadataReportConfig metadataReportConfig = new MetadataReportConfig();
        metadataReportConfig.setAddress("zookeeper://127.0.0.1:2181");
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setId("registry11");
        registryConfig.setAddress("zookeeper://127.0.0.1:2181");
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName("dubbo");
        protocolConfig.setPort(20881);
        HelloWorldService helloWorldService = new HelloWorldService();
        ServiceConfig serviceConfig = new ServiceConfig();
        serviceConfig.setInterface(IHelloWorld.class);
        serviceConfig.setTimeout(3000);
        serviceConfig.setRef(helloWorldService);
        serviceConfig.setRegistry(registryConfig);
        List<MethodConfig> methods = new ArrayList<>();
        MethodConfig methodConfig = new MethodConfig();
        methodConfig.setName("sayHello");
        methodConfig.setCache("");
        methods.add(methodConfig);


        DubboBootstrap bootstrap = DubboBootstrap.getInstance();
        bootstrap.application(applicationConfig)
                .registry(registryConfig)
                .configCenter(centerConfig)
                .metadataReport(metadataReportConfig)
                .protocol(protocolConfig)
                .service(serviceConfig)
                .start()
                .await();
    }
}
